<!DOCTYPE html>
<html class=" js csstransforms3d"><head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>文章发布-发布</title>
	<link rel="stylesheet" href="css/base.css">
	<link rel="stylesheet" href="css/page.css">
	<!--[if lte IE 8]>
	<link href="css/ie8.css" rel="stylesheet" type="text/css"/>
	<![endif]-->
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/main.js"></script>
	<script type="text/javascript" src="js/modernizr.js"></script>
	<script type="text/javascript" src="js/jquery.selectui.js"></script>
	<script type="text/javascript" src="js/layer/layer.js"></script>
	<link rel="stylesheet" type="text/css" href="js/webuploader/webuploader.css">    
    <link rel="stylesheet" type="text/css" href="js/webuploader/demo.css">
	<script type="text/javascript" src="js/laydate/laydate.js"></script>
    <link type="text/css" rel="stylesheet" href="js/laydate/need/laydate.css">
    <link type="text/css" rel="stylesheet" href="js/laydate/skins/default/laydate.css" id="LayDateSkin">
	<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
	<script>
	$(function($) {
		$("select").selectui({
			// 是否自动计算宽度
			autoWidth: true,
			// 是否启用定时器刷新文本和宽度
			interval: true
		});
	});
	</script>
	<!--[if IE]>
	<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
	<![endif]-->
	<script src="js/utf8-jsp/third-party/zeroclipboard/ZeroClipboard.js" type="text/javascript" defer></script></head>

	<body style="background: rgb(246, 245, 250);">
	<!--content S-->
	<div class="super-content">
		
		<div class="superCtab">
			<div class="publishArt">
				<h4>发布一起学</h4>
				<div class="pubMain">
					<a href="javascript:history.go(-1)" class="backlistBtn"><i class="ico-back"></i>返回列表</a>
					<form action="" method="post" id="learnForm">
						<div class="hd-start-end">
							<ul class="clearfix">
								<li>
									<h5 class="pubtitle">选择日期</h5>
									<div class="pub-txt-bar">
										<input type="text" id="infoDateId" class="shuruTxt" onclick="laydate({istime: true, istoday: true, format: 'YYYY-MM-DD'})" name="infoDate" >
									</div>
								</li>
							</ul>
						</div>
						<h5 class="pubtitle">育儿音频标题</h5>
						<div class="pub-txt-bar">
							<input type="text" class="shuruTxt" name="title" id="titleId" maxlength="60">
						</div>
						<h5 class="pubtitle">上传育儿音频</h5>
						<div class="Thumbnails clearfix">
							<div class="Thumblist" id="preview">
							</div>
							<div class="Thumblistbg upload-img"  id="myupload">
								<input class="fileImage" id="fileImage" type="file" onchange="file_ajax_submit();" accept="audio/*">
								<a href="javascript:;" class="Thumbbtn"><i class="ico-download"></i>上传音频</a>
							</div>
						</div>
						<h5 class="pubtitle">育儿音频地址</h5>
						<div class="pub-txt-bar">
							<input type="text" class="shuruTxt" id = "urlId" name="fileSrc" maxlength="300">
							<a class="audition" id= "audition1" href="/learnAdd" target="_blank">试听</a>
						</div>

						<input type="hidden" class="shuruTxt" name = "duration" id="durationId" value="0" maxlength="10">

						<h5 class="pubtitle">育儿音频内容</h5>
						<div class="pub-area-bar">
                            <textarea name="" rows="" cols="3" name = "detail" id="detailId" maxlength="4000"></textarea>
                        </div>
						<h5 class="pubtitle">成长音频标题</h5>
						<div class="pub-txt-bar">
							<input type="text" class="shuruTxt" name="title1" id="title1Id" maxlength="60">
						</div>
						<h5 class="pubtitle">上传成长音频</h5>
						<div class="Thumbnails clearfix">
							<div class="Thumblist" id="preview1">
							</div>
							<div class="Thumblistbg upload-img"  id="myupload1">
								<input class="fileImage" id="fileImage1" type="file" onchange="file_ajax_submit1();" accept="audio/*">
								<a href="javascript:;" class="Thumbbtn"><i class="ico-download"></i>上传音频</a>
							</div>
						</div>
						
						<h5 class="pubtitle">成长音频地址</h5>
						<div class="pub-txt-bar">
							<input type="text" class="shuruTxt" id = "urlId1" name="fileSrc1" maxlength="300">
							<a class="audition" id= "audition2" href="/learnAdd" target="_blank">试听</a>
						</div>

						<input type="hidden" class="shuruTxt" name = "duration1" id="durationId1" value="0" maxlength="10">
			
						<h5 class="pubtitle">成长音频内容</h5>
						<div class="pub-area-bar">
                            <textarea name="" rows="" cols="3" name = "detail1" id="detailId1" maxlength="4000"></textarea>
                        </div>
						
						<h5 class="pubtitle">是否有效</h5>
						<div class="pubselect">
							<span class="select_ui"><span class="select_text_ui" style="min-width: 6em;">是否有效</span><b class="select_arrow"></b>
								<select name="stateType" id="stateTypeId">
								<option value="1">有效</option>
								<option value="0">无效</option>
							</select></span>
						</div>
						<input type="hidden" value="0.0.0.0" name = "operIp" id="ipId">
						<input type="hidden" value="" name = "operUserId" id="userId">
						<div class="pub-btn">
							<input type="button" id="submit" value="发布" class="saveBtn" onclick="submitLearn();">
						</div>
					</form>
				</div>
			</div>
		
		</div>
		<!--main-->
		
	</div>
	<!--content E-->

</body></html>
<script>
    var id = null;
    var currInfoLearn = null;
    $(function(){
        $("#ipId").val(returnCitySN["cip"]);
        $("#userId").val(sessionStorage.getItem("id"));
        id = GetQueryString("id");
        if(id != null){
            getInfoLearnById(id);
            $("#submit").val("修改");
        }
    }.bind(this));
    function getInfoLearnById() {
        $.ajax({
            type: 'POST',
            url: '/getInfoLearnById',
            data: {"id":id},
            dataType:'json',
            success:function(data, status){
                currInfoLearn = data;
                $("#infoDateId").val(data.infoDate);
                $("#stateTypeId").val(data.stateType);
                let infoFiles = data.infoFiles;
                for(let i=0;i<infoFiles.length;i++){
                    let infoFile = infoFiles[i];
                    if(i == 0){
                        $("#titleId").val(infoFile.title);
                        $("#durationId").val(infoFile.duration);
                        $("#detailId").val(infoFile.detail);
                        if(infoFile.fileSrc !=null && infoFile.fileSrc.length > 0){
                            let html = '<div class="Thumb_li" style="background:none; "><div class="bg" style="display: block; "><a href="javascript:" id="delete" class="Thumb_delete" title="删除" >删除</a></div>' +
                                '</div>';
                            $("#preview").html(html);
                            
                            let start =  infoFile.fileSrc.indexOf("knowledge/")+10;
                            let end =  infoFile.fileSrc.indexOf("?")
                            let key  =  infoFile.fileSrc.substring(start,end)
                            $("#delete").click(function(){
                                $(this).parent().parent('.Thumb_li').remove();
                                $("#myupload").show();
                                $("#urlId").val("");
                                deleteImage(key);
                            });
                            $("#myupload").hide();
                            $("#urlId").val(infoFile.fileSrc);
                            $("#audition1").attr("href",infoFile.fileSrc); 
                        }
					}
					if(i==1){
                        $("#title1Id").val(infoFile.title);
                        $("#durationId1").val(infoFile.duration);
                        $("#detailId1").val(infoFile.detail);
                        if(infoFile.fileSrc !=null && infoFile.fileSrc.length > 0){
                            let html = '<div class="Thumb_li" style="background:none; "><div class="bg" style="display: block; "><a href="javascript:"  id="delete1" class="Thumb_delete" title="删除" >删除</a></div>' +
                                '</div>';
                            $("#preview1").html(html);
                            
                           
                            let start =  infoFile.fileSrc.indexOf("knowledge/")+10;
                            let end =  infoFile.fileSrc.indexOf("?")
                            let key  =  infoFile.fileSrc.substring(start,end)
                            $("#delete1").click(function(){
                                $(this).parent().parent('.Thumb_li').remove();
                                $("#myupload1").show();
                                $("#urlId1").val("");
                                deleteImage(key);
                            });
                            $("#myupload1").hide();
                            $("#urlId1").val(infoFile.fileSrc);
                            $("#audition2").attr("href",infoFile.fileSrc);
                        }
					}

				}
            }.bind(this),
            error:function(err, status){
                console.log(err);
            }});
    }
	function submitLearn() {
        let checked = true;
        
        var reg = new RegExp("^[0-9]*$");
       	var obj = document.getElementById("durationId");
       	var obj1 = document.getElementById("durationId1");
       	
        if($('#titleId').val().length ==0){
            alert("请填写育儿音频标题");
            checked = false;
        }else if($("#urlId").val().length ==0){
            alert("请上传育儿音频或者填写育儿音频地址");
            checked = false;
        }else if($("#detailId").val().length ==0){
            alert("请填写育儿音频内容");
            checked = false;
        }else if($('#title1Id').val().length ==0){
            alert("请填写成长音频标题");
            checked = false;
        }else if($("#urlId1").val().length ==0){
            alert("请上传成长音频或者填写成长音频地址");
            checked = false;
        }if(checked){
            var ii = layer.load();
            if(id !=null){
                this.updateLearn();
            }else{
                $.ajax({
                    type: 'POST',
                    url: '/insertInfoLearn',
                    data: $('#learnForm').serialize(),
                    dataType:'json',
                    success:function(data, status){
                        window.location.href = "/learn";
                    }.bind(this),
                    error:function(err, status){
                    }});
            }
            layer.close(ii);
        }
    }
    function updateLearn() {
        currInfoLearn.title = $('#titleId').val()+"|"+$('#title1Id').val();
        currInfoLearn.stateType = $("#stateTypeId").val();
        currInfoLearn.operUserId = $("#userId").val();
        currInfoLearn.infoDate = $("#infoDateId").val();
        let infoFiles = currInfoLearn.infoFiles;
        for(let i=0;i<infoFiles.length;i++){
            let infoFile = infoFiles[i];
            if(i==0){
                infoFile.title = $('#titleId').val();
                infoFile.fileSrc = $("#urlId").val();
                infoFile.duration = "0";
                infoFile.detail = $("#detailId").val();
			}
			if(i==1){
                infoFile.title = $('#title1Id').val();
                infoFile.fileSrc = $("#urlId1").val();
                infoFile.duration = "0";
                infoFile.detail = $("#detailId1").val();
			}
        }
        $.ajax({
            type: 'POST',
            url: '/updateInfoLearn',
            data: JSON.stringify(currInfoLearn),
            dataType:'json',
            contentType : 'application/json',
            success:function(data, status){
                window.location.href = "/learn";
            }.bind(this),
            error:function(err, status){
            }});
    }
    function file_ajax_submit(file) {
    	var ii = layer.load();
        var formData = new FormData();
        formData.append('file', $('#fileImage')[0].files[0]);
        $.ajax({
            url: '/upload',
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function(res) {
            res = JSON.parse(res);
            let html = '<div class="Thumb_li" style="background:none; "><div class="bg" style="display: block; "><a href="javascript:" class="Thumb_delete" id="delete" title="删除" >删除</a></div>' +
                '</div>';
            $("#preview").html(html);
            $("#delete").click(function(){
                $(this).parent().parent('#del').remove();
                $("#myupload").show();
                $("#urlId").val("");
                deleteImage(res.key);
            });
            $("#myupload").hide();
            $("#urlId").val(res.url);
            $("#audition1").attr("href",res.url); 
            layer.close(ii);
        }).fail(function(res) {});
         
    }
    function file_ajax_submit1(file) {
   		var ii = layer.load();
        var formData = new FormData();
        formData.append('file', $('#fileImage1')[0].files[0]);
        $.ajax({
            url: '/upload',
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function(res) {
            res = JSON.parse(res);
            let html = '<div class="Thumb_li" style="background:none; "><div class="bg" style="display: block; "><a href="javascript:" class="Thumb_delete" id="delete1" title="删除" >删除</a></div>' +
            '</div>';
            $("#preview1").html(html);
            
            $("#delete1").click(function(){
                $(this).parent().parent('#del1').remove();
                $("#myupload1").show();
                $("#urlId1").val("");
                deleteImage(res.key);
            });
            $("#myupload1").hide();
            $("#urlId1").val(res.url);
            $("#audition2").attr("href",res.url); 
            layer.close(ii);
        }).fail(function(res) {});
    }
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
</script>
<script language="JavaScript">   
var today=new Date();  
var submitTime=today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();   
$("#infoDateId").attr('value',submitTime);  
</script>